package com.sky.controller.admin.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.service.UserSetmealService;
import com.sky.vo.DishItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/setmeal")
public class UserSetmealController {

    @Autowired SetmealService setmealService;

    /**
     * 根据分类id查询套餐
     *
     * @return {@link Result}
     */
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")// setmealCache::12(key) (val):是具体的返回结果,由spring封装,不用操心
    @GetMapping("/list")
    public Result<List<Setmeal>> list(Long categoryId){
        List<Setmeal> setmealList = setmealService.list(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 根据套餐id查询包含的菜品
     *
     * @param id
     * @return {@link Result}
     */
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVO>> selectDishsBySetmealId(@PathVariable Long id){
        List<DishItemVO> dishItemVOList = setmealService.selectDishsBySetmealId(id);
        return Result.success(dishItemVOList);
    }


}
